		
<script type="text/javascript" src="assets/js/jquery.date-format.js"></script>
<script type="text/javascript" src="assets/js/jquery.form.js"></script>
<script>
	var oImgUploader;
	var oImageForm;
	
	$(document).ready(function(){
		oImgUploader = $("#imageuploader"); 
		oImageForm = $("#imageForm");

		//Dialog box
		oImgUploader.dialog({
				autoOpen: false,
				height: 220,
				width: 380,
				modal: true,
				buttons: {
					"Upload the image": uploadImage,
					Cancel: function(){oImgUploader.dialog("close");}
					},
				close: function(){
					form[0].reset();
					}
				});

		//Image upload form
		oImageForm.submit(function(e){
			var formObj = $(this);
			var formURL = formObj.attr("action");

			if(window.FormData != undefined){ // for HTML5 browser
				alert("HTML5 browser");
				var formData = new FormData(this);
				debugger;
				
				$.ajax({
						url: formURL,
						type: 'POST',
						data: formData,
						mimeType: "multipart/form-data",
						contentType: false,
						cache: false,
						processData: false,
						success: function(data, textStatus,	jqXHR){
							alert(data);
						},
						error: function(jqXHR, textStatus, errorThrown){
							alert("Uploading failed");
						}
				});
				e.preventDefault();
				e.unbind();
			}
			else{	// for old browsers
				alert("Older browser");
				debugger;
				//generate a random id
				var iframeId = 'unique' + (new Data().getTime());

				//create an empty iframe
				var iframe  = $('<iframe src="javascript:false;" name="' + iframeId + '" />');

				//hide it
				iframe.hide();

				//set form target to iframe
				formObj.attr('target', iframeId);

				//Add iframe to body
				iframe.appendTo('body');
				iframe.load(function(e){
						var doc = getDoc(iframe[0]);
						var docRoot = doc.body?doc.body:doc.documentElement;
						var data = docRoot.innerHTML;
					});
			}	
		});
	});
	function onAddImageClick(){
		oImgUploader.dialog("open");	
	}
	function uploadImage(){
		valid = true;
		valid = ($("#newImage").val() != "");
		if(valid){
			
			oImageForm.submit();
			oImgUploader.dialog("close");
		}
		return valid;
	}

	function getDoc(frame){
		var doc = null;

		//IE8 cascading access check
		try{
			if(frame.contentWindow.document){
				doc = frame.contentWindow.document
			}
		}
		catch(err){}

		if(doc){
			return doc;
		}

		try{
			doc = frame.contentDocument?frame.contentDocument:frame.document;
		}
		catch(err){
			doc = frame.document;
		}
		return doc;
	}
</script>

<?php 
if(isset($_SERVER['HTTP_REFERER']))
	printf("<a href=\"%s\" style=\"float:left\">&lt;&lt;Back</a>",$_SERVER['HTTP_REFERER']);
?>
<!-- BEGIN: Image Uploader -->
<div id="imageuploader" title="Image Upload">
	<form id="imageForm" method="POST" enctype="multipart/form-data" action="index.php?dosoap=&upload=">
		<fieldset>
			<label>File name:</label>
			<input type="file"  name="newImage" id="newImage" />
			<input type="hidden" name="dosoap" value="dosoap"/>
			<input type="hidden" name="upload" value="upload"/>
			<input type="hidden" name="playerid" value="<?php echo $playerid;?>"/>		
			<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
		</fieldset>
	</form>
</div>
<!-- END: Image Uploader -->

<br/>
<h3 style="margin-top:5px;float:left;width:70%"><?php printf("%s %s",$player->firstName,$player->lastName); ?></h3>
<div style="width:29%;float:right;margin-top:5px;text-align:right;">
	<?php if($isEditable){
		printf("<a href=\"?editProfile&playerid=%s\">Edit</a>",$playerid);
	}?>
</div>
<div id="blankimage" style="width:70%;float:left;text-align:center;">
	<?php if($noImage){?>
		<div style="margin-top:100px;text-align:center;">
			Image not available.<br/>
			<?php
				if($this->model->isAdmin || (!$this->model->isAdmin && isset($_SESSION["me"]) && $_SESSION["me"]->playerid == $playerid)){ 
					//printf("<a href=\"?managePhotos&playerid=%s\" onclick=\"onAddImageClick();\">Add photos</a>",$playerid);
					printf("<a href=\"#\" onclick=\"onAddImageClick();\">Add photos</a>",$playerid);
				}
			?>	
		</div>
	<?php }
	else{
		printf("<p><img src=\"?display=&photo_id=%d&size=l\" alt=\"%s\"/></p>",$imageData->photoId,$imageData->caption);
		if($this->model->isAdmin || (!$this->model->isAdmin && isset($_SESSION["me"]) && $_SESSION["me"]->playerid == $playerid))
			printf("<a href=\"?managePhotos&playerid=%s\">Edit photos</a><br/>",$playerid);
	}?>
</div>
<style>
	div#towns_display ul.nopadding li div{margin-left:10px;}	
</style>
<div style="width:29%;float:left;padding-left:5px;">
	<div id="towns_display">
		<ul class="nopadding">
			<li><strong>DOB:</strong><br/><div><?php echo date("m/d/Y",strtotime($player->dob));?></div></li>
			<li><strong>From:</strong><br/><div><?php echo $player->homeTown;?></div></li>
			<li><strong>Lives:</strong><br/><div><?php echo $player->currentCity;?></div></li>
			<li><strong>Appearance:</strong><br/>
				<div>
				<?php
					if(count($appearances) > 0) {
						$attendedYears = array();
						foreach($appearances as $event){
							array_push($attendedYears,$event->year);
						}
						echo implode(", ",$attendedYears);
					}
					else{
						echo "This player hasn't participated any event.";
					}
				?>	
				</div>			
			</li>
			<li><strong>Bio</strong><br/><div id="pBio"><?php echo $player->bio;?></div></li>
		</ul>
		
	</div>
</div>
<br style="clear:both"/>
<div style="clear:both;width:100%;margin-top:10px;">
	<table border="1" width="100%">
		<tr>
			<td rowspan="2">Year</td>
			<td colspan="5">Castle Creek</td>
			<td colspan="5">Stone Bridge</td>
			<td colspan="5">Mill Pond</td>
			<td colspan="5">Hago's</td>
			<td colspan="3">Grand</td>
		</tr>
		<tr>
			<td>In</td>
			<td>Out</td>
			<td>Total</td>
			<td>Par</td>
			<td>Hole-in-one</td>
			<td>In</td>
			<td>Out</td>
			<td>Total</td>
			<td>Par</td>
			<td>Hole-in-one</td>
			<td>In</td>
			<td>Out</td>
			<td>Total</td>
			<td>Par</td>
			<td>Hole-in-one</td>
			<td>In</td>
			<td>Out</td>
			<td>Total</td>
			<td>Par</td>
			<td>Hole-in-one</td>
			<td>Total</td>
			<td>Par</td>
			<td>Hole-in-one</td>
		</tr>
		<?php foreach($standings as $row){?>
			<tr>
				<td><?php echo $row["year"];?></td>
				<td><?php echo $row["castleCreekOut"];?></td>
				<td><?php echo $row["castleCreekIn"];?></td>
				<td><?php echo $row["castleCreekTotal"];?></td>
				<td><?php echo $row["castleCreekPar"];?></td>
				<td><?php echo $row["castleCreekHoleInOne"];?></td>
				<td><?php echo $row["stoneBridgeOut"];?></td>
				<td><?php echo $row["stoneBridgeIn"];?></td>
				<td><?php echo $row["stoneBridgeTotal"];?></td>
				<td><?php echo $row["stoneBridgePar"];?></td>
				<td><?php echo $row["stoneBridgeHoleInOne"];?></td>
				<td><?php echo $row["millPondOut"];?></td>
				<td><?php echo $row["millPondIn"];?></td>
				<td><?php echo $row["millPondTotal"];?></td>
				<td><?php echo $row["millPondPar"];?></td>
				<td><?php echo $row["millPondHoleInOne"];?></td>
				<td><?php echo $row["hagosOut"];?></td>
				<td><?php echo $row["hagosIn"];?></td>
				<td><?php echo $row["hagosTotal"];?></td>
				<td><?php echo $row["hagosPar"];?></td>
				<td><?php echo $row["hagosHoleInOne"];?></td>
				<td><?php echo $row["grandTotal"];?></td>
				<td><?php echo $row["grandPar"];?></td>
				<td><?php echo $row["grandHoleInOne"];?></td>
			</tr>
		<?php }?>
	</table>
</div>
